package chapter03
import org.apache.spark.{SparkConf, SparkContext}
object Test12_ClickNumber {
  def main(args: Array[String]): Unit = {
    val number = new SparkConf().setMaster("local[*]").setAppName("Number")
    val sc = new SparkContext(number)
    //读取文件
    val value = sc.textFile("input/apache.log")
    //统计每天的访问数量
    println(value.map(e=>e.split(" ")(3))
      .map(e=>e.split(":")(0))
      .groupBy(e=>e)
      .map(e=>(e._1,e._2.size))
      .collect().mkString("Array(", ", ", ")"))
    //统计每天每个IP的访问次数
    println(value.map{
      e=>{
        val strings = e.split(" ")
        (strings(0),strings(3).split(":")(0))
        }
      }
      .groupBy(e=>e)
      .map(e=>(e._1,e._2.size))
      .collect().mkString("Array(", ", ", ")"))
  }
}
